﻿using Furion.DynamicApiController;
using Gear.Core.AOP.Filter;
using Gear.Web.Api.DynamicRouter;
using Microsoft.AspNetCore.Mvc;
using System;



// 动态路由实现

namespace Gear.Web.Tests.Characteristic
{
    #region ==动态路由基本配置==

    /// <summary>
    /// 动态路由实现（特性模式）
    /// </summary>
    [DynamicApiController]
    [TestAsync]
    [ApiDescriptionSettings("DynamicRoute")]
    
    public class CharacteristicRouterAppService
    {
        /// <summary>
        /// Get请求
        /// </summary>
        /// <returns></returns>
        public string Get()
        {
            return $"GET 请求";
        }
        /// <summary>
        /// Post请求
        /// </summary>
        /// <returns></returns>
        public string Post()
        {
            return $"POST 请求";
        }
        /// <summary>
        /// Delete请求
        /// </summary>
        /// <returns></returns>
        public string Delete()
        {
            return $"DELETE 请求";
        }
        /// <summary>
        /// Put请求
        /// </summary>
        /// <returns></returns>
        public string Put()
        {
            return $"PUT 请求";
        }
        /// <summary>
        /// Patch请求
        /// </summary>
        /// <returns></returns>
        public string Patch()
        {
            return $"PATCH 请求";
        }
        /// <summary>
        /// 带参数请求
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public string GetUser(int id, string name)
        {
            return $"{id} {name}";
        }
    }

    /// <summary>
    /// 动态路由实现（继承模式）
    /// </summary>
    [ApiDescriptionSettings("DynamicRoute")]
    
    public class InheritRouterAppService : IDynamicApiController
    {
        /// <summary>
        /// Get请求
        /// </summary>
        /// <returns></returns>
        public string Get()
        {
            return $"GET 请求";
        }
        /// <summary>
        /// Post请求
        /// </summary>
        /// <returns></returns>
        public string Post()
        {
            return $"POST 请求";
        }
        /// <summary>
        /// Delete请求
        /// </summary>
        /// <returns></returns>
        public string Delete()
        {
            return $"DELETE 请求";
        }
        /// <summary>
        /// Put请求
        /// </summary>
        /// <returns></returns>
        public string Put()
        {
            return $"PUT 请求";
        }
        /// <summary>
        /// Patch请求
        /// </summary>
        /// <returns></returns>
        public string Patch()
        {
            return $"PATCH 请求";
        }
        /// <summary>
        /// 带参数请求
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public string GetUser(int id, string name)
        {
            return $"{id} {name}";
        }
    }

    /// <summary>
    /// 动态路由实现（自定义模式）
    /// </summary>
    [ApiDescriptionSettings("DynamicRoute")]
    
    public class CustomRouterAppService : IDynamicRoute
    {
        /// <summary>
        /// Get请求
        /// </summary>
        /// <returns></returns>
        public string Get()
        {
            return $"GET 请求";
        }
        /// <summary>
        /// Post请求
        /// </summary>
        /// <returns></returns>
        public string Post()
        {
            return $"POST 请求";
        }
        /// <summary>
        /// Delete请求
        /// </summary>
        /// <returns></returns>
        public string Delete()
        {
            return $"DELETE 请求";
        }
        /// <summary>
        /// Put请求
        /// </summary>
        /// <returns></returns>
        public string Put()
        {
            return $"PUT 请求";
        }
        /// <summary>
        /// Patch请求
        /// </summary>
        /// <returns></returns>
        public string Patch()
        {
            return $"PATCH 请求";
        }
        /// <summary>
        /// 带参数请求
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public string GetUser(int id, string name)
        {
            return $"{id} {name}";
        }
    }

    #endregion

    #region ==路由配置==
    /// <summary>
    /// 路由顺序配置
    /// </summary>
    [DynamicApiController]
    [ApiDescriptionSettings("DynamicRoute")]
    
    public class RouterSettings
    {
        // 参数默认为 ApiSeats.ActionEnd
        /// <summary>
        /// 路由参数配置（默认）
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public string RouteSeat(int id, string name)=> "配置路由参数位置";

        /// <summary>
        /// 路由参数配置
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <param name="age"></param>
        /// <param name="weight"></param>
        /// <param name="height"></param>
        /// <param name="birthday"></param>
        /// <returns></returns>
        public string RouteSeat(
            [ApiSeat(ApiSeats.ControllerStart)] int id, // 控制器名称之前
            [ApiSeat(ApiSeats.ControllerEnd)] string name, // 控制器名称之后
            [ApiSeat(ApiSeats.ControllerEnd)] int age, // 控制器名称之后
            [ApiSeat(ApiSeats.ActionStart)] decimal weight, // 动作方法名称之前
            [ApiSeat(ApiSeats.ActionStart)] float height, // 动作方法名称之前
            [ApiSeat(ApiSeats.ActionEnd)] DateTime birthday) // 动作方法名称之后（默认值）
        {
            return "配置路由参数位置";
        }
    }

    /// <summary>
    /// 路由命名配置
    /// </summary>
    [DynamicApiController]
    [ApiDescriptionSettings(Name = "RouterSettingsV1")]
    
    public class RouterSettingsV0
    {
        /// <summary>
        /// Get=>RouteSeat
        /// </summary>
        /// <returns></returns>
        [ApiDescriptionSettings(Name = "RouteSeat")]
        public string Get()=> nameof(Gear);
    }


    /// <summary>
    /// 保持控制器和方法命名
    /// </summary>
    [DynamicApiController]
    [ApiDescriptionSettings(KeepName = true)]
    
    public class RouterSettingsV2
    {
        /// <summary>
        /// 保持Get
        /// </summary>
        /// <returns></returns>
        [ApiDescriptionSettings(KeepName = true)]
        public string Get()=>nameof(Gear);
    }

    #endregion


}
